package com.spring.security.study.security_test.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户未登录处理类
 * @Author: 王文龙
 * @Date: 2020/7/610:06
 * @Version: 1.0
 * @Describe: 描述:
 */
@Slf4j
@Component
public class UserAuthenticationEntryPointHandler implements AuthenticationEntryPoint {


    /**
     *
     * @param httpServletRequest 导致了<code>身份验证异常
     * @param httpServletResponse 以便用户代理可以开始身份验证
     * @param e 引发了这场召唤
     * @throws IOException 抛异常
     * @throws ServletException 抛异常
     */
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 401);
        map.put("msg", "未登录");
        log.info("数据:{}",map);
    }
}
